package com.jimmy.nonweb.data.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.jimmy.nonweb.data.entity.Engineer;
import java.util.List;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.mapping.FetchType;

public interface EngineerMapper extends BaseMapper<Engineer> {

    @Results(id = "engineerResults", value = {
        @Result(property = "id", column = "id"),
        @Result(property = "engineerFullname", column = "engineer_fullname"),
        @Result(property = "accounts", javaType = List.class, column = "id",
                many = @Many(select = "com.jimmy.nonweb.data.mapper.AccountMapper.selectByEngineerId", fetchType = FetchType.LAZY))
    })
    @Select("SELECT * FROM engineer")
    List<Engineer> selectAllWithAccounts();

    @ResultMap("engineerResults")
    @Select("SELECT * FROM engineer WHERE id = #{id}")
    Engineer selectByIdWithAccounts(String id);
}
